package com.itheima.confige;

import com.itheima.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/*
*  注册拦截器
* 4*/
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //将拦截器注册到spring ioc容器
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }
    /*
    *  重写该方法；往拦截器链添加自定义拦截器
    *   @param registry 拦截器链
    * */
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(myInterceptor()).addPathPatterns("/*");
    }
}
